package com.tianchi.lexiang.background.util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import jxl.Sheet;
import jxl.Workbook;

import android.util.Log;

import com.tianchi.lexiang.bean.Song;

public class ReaderSongExcle {
	
	private static final String TAG = "ReaderSongExcle";
	
	private static ReaderSongExcle instance = null;
	private Workbook workbook = null;
	private Sheet sheet = null;
	
	private ReaderSongExcle(){
		
	}
	
	public static ReaderSongExcle getInstance(){
		if(instance == null){
			instance = new ReaderSongExcle();
		}
		return instance;
	}
	
	public List<Song> getAllSongsInfo(String path){
		List<Song> list = new ArrayList<Song>();
		File file = new File(path);
		boolean bool = file.exists();
		Log.d(TAG, "[getAllSongsInfo].....bool==>" + bool);
		if(bool){
			try {
				workbook = Workbook.getWorkbook(file);
			} catch (Exception e) {
				e.printStackTrace();
				Log.d(TAG, "[getAllSongsInfo]....e====>" + e.toString());
			}
			sheet = workbook.getSheet(0);
			int rowCount = sheet.getRows();
			Log.d(TAG, "[getAllSongsInfo]....rowCount=== > " + rowCount);
			for(int i = 1; i< rowCount; i++){
				Song song = new Song();
				song.songName = sheet.getCell(0, i).getContents();
				song.singerName = sheet.getCell(1, i).getContents();
				song.language = sheet.getCell(2, i).getContents();
				song.type = sheet.getCell(3, i).getContents();
				song.mtvOrVcd = sheet.getCell(4, i).getContents();
				song.firstSpell = sheet.getCell(5, i).getContents();
				if("".equals(sheet.getCell(6, i).getContents()) || sheet.getCell(6, i).getContents() == null){
					song.nameLength = 0;
				}else{
					song.nameLength = Integer.parseInt(sheet.getCell(6, i).getContents());
				}
				if("".equals(sheet.getCell(7, i).getContents()) || sheet.getCell(7, i).getContents() == null){
					song.leftArea = 50;
				}else{
					song.leftArea = Integer.parseInt(sheet.getCell(7, i).getContents());
				}
				if("".equals(sheet.getCell(8, i).getContents()) || sheet.getCell(8, i).getContents() == null){
					song.rightArea = 50;
				}else{
					song.rightArea = Integer.parseInt(sheet.getCell(8, i).getContents());
				}
				song.lyrics = sheet.getCell(9, i).getContents();
				song.lyricsFirstSpell = sheet.getCell(10, i).getContents();
				if("".equals(sheet.getCell(11, i).getContents()) || sheet.getCell(11, i).getContents() == null){
					song.temp = 0;
				}else{
					song.temp = Integer.parseInt(sheet.getCell(11, i).getContents());
				}
				song.date = sheet.getCell(12, i).getContents();
				song.format = sheet.getCell(13, i).getContents();
				list.add(song);
			}
		}
		
		return list;
		
	}
}
